package com.example.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Question UserController
 * @Date 2023/1/4 11:04
 * @Solution
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @RequestMapping("/login")
    public boolean login(String username, String password, HttpServletRequest request) {
        //非空判断
        if(username!=null && !username.equals("") && password!=null && !password.equals("")) {
            if(username.equals("admin") && password.equals("admin")) {
                HttpSession session = request.getSession();
                session.setAttribute("userinfo","admin");
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    @RequestMapping("/getinfo")
    public String getInfo() {
        log.debug("getInfo");
        return "getInfo";
    }
    @RequestMapping("/reg")
    public String reg() {
        log.debug("reg");
        return "reg";
    }
}
